package com.mapbased.wfw.components;

import java.io.*;
import java.util.*;

import org.dom4j.*;
import com.mapbased.wfw.*;

/**
 *
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 *
 * *
 * <p>Copyright: Copyright (c) 2004</p>
 *
 * <p>Company: mapbased.com</p>
 *
 * @author chy_hs(Baily)
 * @version 1.0
 */
/***
 *
 * Format:
 * <Element jwcid="com.mapbased.wfw.components.MenuBar" >
 *     <Ele jwcid="menudata" caption="the caption" url="/pages/company/about.html" sid="/company">
 *     <Ele jwcid="menudata" caption="the caption" url="/pages/company/about.html" sid="/company">
 *     <Ele jwcid="menudata" caption="the caption" url="/pages/company/about.html" sid="/company">
 *     <Ele jwcid="menudata" caption="the caption" url="/pages/company/about.html" sid="/company">
 *     <Ele jwcid="menudata" caption="the caption" url="/pages/company/about.html" sid="/company">
 *
 *   <td jwcid="selecteditem">
 *     <a href="@var{menudata.url}"> @var{menudata.caption}</a>
 *   </td>
 *   <td jwcid="unselecteditem">
 *     <a href="@var{menudata.url}"> @var{menudata.caption}</a>
 *   </td>
 *
 *
 *
 * </Element>
 *
 * menudata Eleement will retrieve by the component and then delete from the element
 *
 *
 *Another format:(the current used modle)
 *
 *
 *<table jwcid="com.mapbased.wfw.components.MenuBar" >
 * <tr>
 *   <td jwcid="selecteditem">
 *     <a href="/pages/company/about.html" class="select_@component{selectTab.isSelected(/page)}" >the caption</a>
 *     <a href="/pages/company/about.html">the caption</a>
 *     <a href="/pages/company/about.html">the caption</a>
 *     <a href="/pages/company/about.html">the caption</a>
 *     <a href="/pages/company/about.html">the caption</a>
 *     <a href="/pages/company/about.html">the caption</a>
 *     <a href="/pages/company/about.html">the caption</a>
 *
 *   </td>
 * </tr>
 *
 *
 * </table>
 *

 *
 *
 */


public class MenuBar
    extends TemplateComponent
{

    public static class TmpRetObj
    {
        String path;
        TmpRetObj(String path)
        {
            this.path=path;
        }

        public boolean isSelected(String page)
        {
            return path.startsWith(page);
        }

    }

    private TmpRetObj tmpRetObj=null;
    public Object selectTabBinding(final RenderContext context)
    {
        if(tmpRetObj == null)
        {
            this.tmpRetObj=new TmpRetObj(context.getRequest().getServletPath());
        }
        return this.tmpRetObj;

    }

}
